﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace rbdesign.Model
{
    class ModelCRUD
    {
        static SqlConnection scDatabaseConnection = new SqlConnection(rbdesign.Properties.Settings.Default.rbDatabaseConnectionString);

        public static DataTable Select(string sQuery)
        {
            try
            {
                scDatabaseConnection.Open();
                SqlCommand scmdCommand = new SqlCommand(sQuery, scDatabaseConnection);
                SqlDataAdapter sdaTableAdapter = new SqlDataAdapter(scmdCommand);
                DataTable dt = new DataTable();
                sdaTableAdapter.Fill(dt);
                return dt;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                scDatabaseConnection.Close();
            }
        }

        public static void InsertUpdateDelete(string sQuery)
        {
            try
            {
                scDatabaseConnection.Open();
                SqlCommand scmdCommand = new SqlCommand(sQuery, scDatabaseConnection);

                scmdCommand.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                scDatabaseConnection.Close();
            }
        }
    }
}
